import QtQuick 2.11
import QtQuick.Window 2.2
import Qt.labs.platform 1.0
import QtQuick.Controls 2.4
import QtQuick.Controls.Material 2.3

ApplicationWindow {
    id:mainwindow
    visible: true
    width: 640
    height: 640
    title: qsTr("Mainwindow")
    background: Rectangle{
        color: "#f0f7f6"
        anchors.fill: parent
        radius: 30
    }
    menuBar: MenuBar{

        Menu{
            title: qsTr("import")

            MenuItem{
                text:qsTr("config")
                onTriggered: {
                    fileDialog.mission="loadConfig";
                    fileDialog.open();

                    //buttonChooseConfigFile.text = qsTr("config");
                }
            }

            MenuItem{
                text:qsTr("record")
                onTriggered: {
                    fileDialog.mission="loadRecord";
                    fileDialog.open();
                }
            }

        }

    }

    FileDialog{
        id:fileDialog
        property string mission: "";
        onAccepted: {
            var filepath=String(file).slice(8);
            if(mission==="loadConfig"){
                //MainController.loadConfig(filepath);
                pageXmlParseConfig.adjustJsonButton(JsonAnalyze.getFileName(filepath));
                JsonAnalyze.analyzFile(filepath);
            }

            else if(mission==="loadRecord"){
                pageXmlParseConfig.adjustXmlButton(JsonAnalyze.getFileName(filepath));
                //MainController.readRecord(filepath);

            }
        }
    }

    header: TabBar {
        width: parent.width
        id: tabBar
        currentIndex: swipeView.currentIndex
        Repeater {
            model: [qsTr("XmlParse"),qsTr("Database")]
            TabButton {
                text: modelData
            }
        }
    }

    Column{
        id:mainColumn
        anchors.fill:  parent
        TabBar{
            width: parent.width;
            height: 20;
            TabButton{

            }
        }
        SwipeView {
            id: swipeView
            width: parent.width
            height: parent.height-scrollView.height
            currentIndex: tabBar.currentIndex
            PageXmlParseConfig {
                id: pageXmlParseConfig
            }
            PageDatabaseConfig {
                id: pageDatabaseConfig
            }
        }
        ScrollView{
            id:scrollView
            width: parent.width
            height: switchConcole.checked?200:0;
            visible: switchConcole.checked
            ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
            ScrollBar.vertical.policy: ScrollBar.AlwaysOn
            ScrollBar.vertical.interactive: true
            TextArea {
                id: outputArea
                height: 200
                width: parent.width
                padding: 10
                wrapMode: TextEdit.Wrap
                background: Rectangle{
                    color: "#90dae0"
                    anchors.fill:parent

                }
                onTextChanged: {
                    //                    height=lineCount*20;
                    scrollView.contentHeight=height+20;

                }
            }
        }


    }

    Switch {
        id: switchConcole
        text: qsTr("Switch Console")

            anchors.right: parent.right
            anchors.top: parent.top

    }

    Component.onCompleted: {
        MainController.signalDebuging.connect(function(msg){
            outputArea.append(msg);
        });
    }
}

/*##^## Designer {
    D{i:34;anchors_width:40}
}
 ##^##*/
